package bill.study.collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class ListIterating {
	
	public  static void main(String [] args){
		trimByForLoop();
		trimByIterator();
		trimByListIterator();
	}
	
	private static void trimByForLoop(){
		System.out.println("trim by for for loop");
		List<StringBuffer> list = new ArrayList<StringBuffer>();
		list.add(new StringBuffer("Bill"));
		list.add(new StringBuffer("Tony"));
		
		for(StringBuffer str: list){
			str.reverse();
			System.out.println(str);
		}
	}
	
	private static void trimByIterator(){
		System.out.println("trimByIterator");
		List<StringBuffer> list = new ArrayList<StringBuffer>();
		list.add(new StringBuffer("Bill"));
		list.add(new StringBuffer("Tony"));
		
		for(Iterator<StringBuffer> it = list.iterator(); it.hasNext();){
			StringBuffer sb = it.next();
			sb.reverse();
			it.remove();
//		    System.out.println( sb);
		}
		  System.out.println( list);
	}
	
	
	private static void trimByListIterator(){
		System.out.println("trimByListIterator");
		List<StringBuffer> list = new ArrayList<StringBuffer>();
		list.add(new StringBuffer("Bill"));
		list.add(new StringBuffer("Tony"));
		
		for(ListIterator<StringBuffer> it = list.listIterator(); it.hasNext();){
			StringBuffer sb = it.next();
			sb.reverse();
		    System.out.println( sb);
		}
		
	}
	

}
